package com.vdimitr.happycube.puzzle.matrix.bycolor;

import java.util.HashMap;
import java.util.Map;

import com.vdimitr.happycube.puzzle.piece.PuzzlePieceColor;

/**
 * This class is responsible for retrieving the matrix representation of a
 * puzzle piece based on its color and number.
 * 
 * @author vasileios.dimitriadis
 * 
 */
public class PuzzlePieceMatrixRetriever {

	/**
	 * An association between color and matrix representation
	 */
	private Map<PuzzlePieceColor, PuzzlePieceMatrices> puzzlePieceMatricesByColor = new HashMap<PuzzlePieceColor, PuzzlePieceMatrices>();

	/**
	 * Default constructor
	 */
	public PuzzlePieceMatrixRetriever() {
		puzzlePieceMatricesByColor.put(PuzzlePieceColor.BLUE,
				new BluePuzzlePieceMatrices());
		puzzlePieceMatricesByColor.put(PuzzlePieceColor.RED,
				new RedPuzzlePieceMatrices());
		puzzlePieceMatricesByColor.put(PuzzlePieceColor.PURPLE,
				new PurplePuzzlePieceMatrices());
		puzzlePieceMatricesByColor.put(PuzzlePieceColor.YELLOW,
				new YellowPuzzlePieceMatrices());
		puzzlePieceMatricesByColor.put(PuzzlePieceColor.NULL,
				new NullPuzzlePieceMatrices());
	}

	/**
	 * Retrieves the matrix representation of a puzzle piece based on color and
	 * number
	 * 
	 * @param color
	 *            the color family
	 * @param puzzlePieceNumber
	 *            the number of the puzzle piece
	 * @return the matrix representation of a puzzle piece with the specified
	 *         color and number
	 */
	public int[][] getMatrix(PuzzlePieceColor color, int puzzlePieceNumber) {
		PuzzlePieceMatrices coloredPuzzlePieceMatrices = this.puzzlePieceMatricesByColor
				.get(color);
		return coloredPuzzlePieceMatrices
				.getPuzzlePieceMatrix(puzzlePieceNumber);
	}

}
